package com.ys.web.user.friends.service.impl;

import com.ys.base.BaseConstants;
import com.ys.utils.base.j2se.DateUtil;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.config.SystemError;
import com.ys.web.user.friends.mapper.GroupApplyMapper;
import com.ys.web.user.friends.po.BaseGroupApplyPO;
import com.ys.web.user.friends.service.GroupApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author quxinjun
 * @version 1.0.0
 * @ClassName GroupApplyServiceImpl.java
 * @Description TODO
 * @createTime 2022年02月23日 21:34:00
 */
@Service
public class GroupApplyServiceImpl implements GroupApplyService {

    @Autowired
    private GroupApplyMapper groupApplyMapper;

    @Override
    public void addGroupApply(Long uid) {
        BaseGroupApplyPO baseGroupApplyPO = groupApplyMapper.selectByUid(uid);
        if (StringHandler.isNotEmpty(baseGroupApplyPO)) {
            SystemError.wrapBs("500", "审核中，请勿重复申请");
        }
        BaseGroupApplyPO info = new BaseGroupApplyPO();
        info.setUserId(uid);
        info.setStatus(false);
        info.setCreateTime(DateUtil.getDate(new Date(), BaseConstants.BASE_FORMAT));
        groupApplyMapper.insertSelective(info);
    }

    @Override
    public Boolean getApplyStatus(Long uid) {
        BaseGroupApplyPO baseGroupApplyPO = groupApplyMapper.selectByUid(uid);
        if (StringHandler.isEmpty(baseGroupApplyPO)) {
            return false;
        }
        return baseGroupApplyPO.getStatus();
    }
}
